package com.tc.bean;

import cn.hutool.core.util.NumberUtil;
import cn.hutool.core.util.ReflectUtil;
import cn.hutool.core.util.StrUtil;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import lombok.extern.slf4j.Slf4j;

import java.io.IOException;
import java.lang.reflect.Method;
import java.util.Objects;

@Slf4j
public class JacksonEnumSerializer extends JsonSerializer<IEnum> {
    @Override
    public void serialize(IEnum value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
        //Method[] methods = ReflectUtil.getMethods(value.getClass(), item -> StrUtil.startWith(item.getName(), "get"));
        //gen.writeStartObject();
//        for (Method method : methods) {
//            String name = method.getName();
//            if (!StrUtil.equals(method.getName(), "getMyValue", false)){
//                continue;
//            }
//            // 首字母小写
//            name = name.substring(0, 1).toLowerCase() + name.substring(1);
//            Object invoke = ReflectUtil.invoke(value, method);
//            gen.writeObject(invoke);
//            gen.writeStringField("a","tianchao");
//            break;
//        }
        Object myValue = value.getMyValue();
        gen.writeObject(myValue);
        gen.writeStringField("a","tianchao");
        //gen.writeEndObject();
    }
}
